﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CMN.BLL;
using CMN.Common;
using CMN.Entity;
using CMN.Models.Interfaces;
namespace CMN.Models
{
    /// <summary>
    /// 标签Service
    /// </summary>
    public class Normal_TagsService: IDataService<Normal_TagsEntity>
    {
        /// <summary>
        /// 新增标签
        /// </summary>
        /// <param name="Normal_TagsEntity"></param>
        /// <returns>string</returns>
        public string Insert(Normal_TagsEntity normal_tagsEntity)
        {
            normal_tagsEntity.DataTable_Action = DataTableAction.Insert;
            Normal_Tags bll = new Normal_Tags();
            int rInt = bll.InsertUpdateDelete(normal_tagsEntity);
            if (rInt > 0)
            {
                return rInt.ToString();
            }
            else
            {
                return "0";
            }
        }

        /// <summary>
        /// 返回标签查询列表
        /// </summary>
        /// <param name="qp"></param>
        /// <param name="count">查询总个数</param>
        /// <returns>List</returns>
        public List<Normal_TagsEntity> List(QueryParam qp,out int count)
        {
            Normal_Tags bll = new Normal_Tags();
            return bll.List(qp, out count);
        }

        /// <summary>
        /// 更新标签
        /// </summary>
        /// <param name="Normal_Tags"></param>
        /// <returns>string</returns>
        public string Update(Normal_TagsEntity normal_tagsEntity)
        {
            normal_tagsEntity.DataTable_Action = DataTableAction.Update;
            Normal_Tags bll = new Normal_Tags();
            if (bll.InsertUpdateDelete(normal_tagsEntity) > 0)
            {
                  return "";
            }
            else
            {
                return "失败";
            }
        }

        /// <summary>
        /// 删除标签
        /// </summary>
        /// <param name="Normal_Tags"></param>
        /// <returns>string</returns>
        public string Delete(Normal_TagsEntity normal_tagsEntity)
        {
            Normal_Tags bll = new Normal_Tags();
            normal_tagsEntity.DataTable_Action = DataTableAction.Delete;
            Normal_TagMap bllTagMap = new Normal_TagMap();
            QueryParam qp=new QueryParam();
            qp.PageIndex=1;
            qp.PageSize=1;
            qp.Where=string.Concat("tagId=",normal_tagsEntity.Id);
            int recordNum=0;
            bllTagMap.List(qp, out recordNum);
            if (recordNum > 0)
            {
                return "请先删除Tag相关文章";
            }
            if (bll.InsertUpdateDelete(normal_tagsEntity) > 0)
            {
                  return "";
            }
            else
            {
                return "失败";
            }
        }

        /// <summary>
        /// 批量删标签
        /// </summary>
        /// <param name="idList">删除id列表  2_8_9_45</param>
        /// <returns>string</returns>
        public string DeleteList(string idList)
        {
            string[] list =Utils.SplitString(idList,"_");
            string strDel=Utils.ArrayToString(list,",",false);
            Normal_Tags bll = new Normal_Tags();
            if (bll.DelList(strDel) > 0)
            {
                 return "";
            }
            else
            {
                return "失败";
            }

        }

        /// <summary>
        /// 返回单个标签
        /// </summary>
        /// <param name="id"></param>
        /// <returns>Normal_TagsEntity</returns>
        public Normal_TagsEntity Look(int id)
        {
            Normal_Tags bll = new Normal_Tags();
            return bll.Disp(id);
        }
    }
}
